//
//  ALPS_PlayNavigationController.m
//  Alps
//
//  Created by dllo on 16/6/21.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ALPS_PlayNavigationController.h"
#import "ALPS_PlayButtonView.h"
#import "ALPS_PlayerMainViewController.h"

@interface ALPS_PlayNavigationController ()<PlayButtonViewDelegate>
@property (nonatomic, strong) ALPS_PlayButtonView *playView;
@property (nonatomic, copy) NSString *imageName;
/** 播放页Id */
@property (nonatomic, assign) NSInteger trackId;
/** 播放页存放model数组 */
@property (nonatomic, strong) NSMutableArray *listArr;
/** 广播网址 */
@property (nonatomic, copy) NSString *radioURL;
/** 广播名称 */
@property (nonatomic, copy) NSString *radioName;
/** 广播背景图片 */
@property (nonatomic, copy) NSString *radioImg;
@end

@implementation ALPS_PlayNavigationController

- (void)dealloc
{
    // 关闭消息中心
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    //通知中心传过来trackId(播放页网络请求参数),listArray(播放列表),imageString(播放按钮图片)
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(trackId:) name:@"trackId" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(listArr:) name:@"listArr" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(radioURL:) name:@"radioURL" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(radioImg:) name:@"radioImg" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(radioName:) name:@"radioName" object:nil];
    
    // 开启两个通知接收
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hidePlayView:) name:@"hidePlayView" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showPlayView:) name:@"showPlayView" object:nil];
    
    self.playView = [[ALPS_PlayButtonView alloc] init];
    self.playView.delegate = self;
    [self.view addSubview:_playView];
    
    self.playView.frame = CGRectMake((ScreeWidth - 65) / 2, ScreeHeight - 65, 65, 65);
}

- (void)trackId:(NSNotification *)notification
{
    self.trackId = [notification.object integerValue];
}

- (void)listArr:(NSNotification *)notification
{
    self.listArr = (NSMutableArray *)notification.object;
}

- (void)radioURL:(NSNotification *)notification
{
    self.radioURL = (NSString *)notification.object;
}

- (void)radioImg:(NSNotification *)notification
{
    self.radioImg = (NSString *)notification.object;
}

- (void)radioName:(NSNotification *)notification
{
    self.radioName = (NSString *)notification.object;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)playButtonDidClick:(BOOL)isSelected
{
    ALPS_PlayerMainViewController *play = [[ALPS_PlayerMainViewController alloc] init];
    if (self.radioURL) {
        play.radioURL = self.radioURL;
        play.radioName = self.radioName;
        play.pictureURL = self.radioImg;
        play.isRedioYesOrNo = YES;
    } else {
        play.trackId = self.trackId;
        play.listArr = self.listArr;
    }
    [self pushViewController:play animated:YES];
}

// 隐藏图片
- (void)hidePlayView:(NSNotification *)notification
{
    self.playView.hidden = YES;
}

// 显示图片
- (void)showPlayView:(NSNotification *)notification
{
    self.playView.hidden = NO;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
